<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div#top{
            width: 100px;
            height: 100px;
            background-color: red;
        }
        div#bottom{
            width: 200px;
            height: 200px;
            background-color: blue;
        }
        div{
            margin: 20px;

        }
    </style>
    <script>
        window.onload=function(){
            var top=document.getElementById('top');
            var bottom=document.getElementById('bottom');
            top.ondragstart=function(event){
                console.log('开始拖动top');
                // console.log(this);
                var data=event.dataTransfer;
                // console.log(data);
                data.setData('top',this.id);

            }
            // top.ondrag=function(){
            //     console.log('一直drag中')
            // }
            // top.ondragend=function(){
            //     console.log('拖放结束啦');
            // }
            // bottom.ondragenter=function(){
            //     console.log('有元素进入bottom');
            // }
            bottom.ondragover=function(event){
                event.preventDefault();
                console.log("top在bottom之上");
            }
            bottom.ondrop=function(event){
                var data=event.dataTransfer;
                //获取top id
                var id=data.getData('top');
                //根据top id 获取dom元素
                var source=document.getElementById((id));
                //将source插入到bottom中
                this.appendChild(source);
                // console.log('id');
                console.log('top放在了bottom中');


            }

        }
    </script>
</head>
<body>
    <div id="top" draggable="true"></div>
    <div id="bottom"></div>

    </p>
</body>
</html>